<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import { House, Box, Help, Setting, Operation } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";

const router = useRouter();
const active = ref("/home");
const activeChange = (path: string) => {
  console.log("activeChange");
  active.value = path;
  router.push(path);
};

watch(active, (old: string, newData: string) => {
  console.log(old, newData);
});

onMounted(() => {
  active.value = `/${window.location.pathname.split("/")[1]}`;
});
</script>

<template>
  <div class="layout">
    <div class="fs-nav-bar">
      <div class="fs-nav-bar_header">
        <div class="img-item">
          <img class="my-element" src="/assets/images/哈士奇.png" alt="" />
          <!-- <img class="animate__animated animate__flipInX" src="/assets/images/哈士奇.png" alt="" /> -->
        </div>
      </div>
      <div class="fs-nav-bar_list">
        <div class="nav-item" @click="() => activeChange('/home')">
          <span :class="{ text: true, 'text-active': active === '/home' }"
            >首页</span
          >
          <el-icon
            :class="{ 'item-icon': true, 'icon-active': active === '/home' }"
          >
            <House />
          </el-icon>
        </div>
        <div class="nav-item" @click="() => activeChange('/tools')">
          <span :class="{ text: true, 'text-active': active === '/tools' }"
            >工具</span
          >
          <el-icon
            :class="{ 'item-icon': true, 'icon-active': active === '/tools' }"
          >
            <Box />
          </el-icon>
        </div>
        <div class="nav-item" @click="() => activeChange('/game')">
          <span :class="{ text: true, 'text-active': active === '/game' }"
            >游戏</span
          >
          <el-icon
            :class="{ 'item-icon': true, 'icon-active': active === '/game' }"
          >
            <Help />
          </el-icon>
        </div>
        <div class="nav-item" @click="() => activeChange('/setting')">
          <span :class="{ text: true, 'text-active': active === '/setting' }"
            >设置</span
          >
          <el-icon
            :class="{ 'item-icon': true, 'icon-active': active === '/setting' }"
          >
            <Setting />
          </el-icon>
        </div>
        <div class="nav-item" @click="() => activeChange('/myThree')">
          <span :class="{ text: true, 'text-active': active === '/myThree' }"
            >three.js</span
          >
          <el-icon
            :class="{ 'item-icon': true, 'icon-active': active === '/myThree' }"
          >
            <Operation />
          </el-icon>
        </div>

        <!--      <div @click="()=>console.log(active)">查看</div>-->
      </div>
    </div>
    <div style="width: 100%"><NuxtPage /></div>
  </div>
</template>

<style lang="scss" scoped>
.layout {
  display: flex;
  .fs-nav-bar {
    width: 10%;
    min-width: 200px;
    border-right: 1px #eeeeee solid;
    height: 100vh;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;

    .fs-nav-bar_header {
      height: 140px;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      font-size: 35px;
      font-weight: 700;

      .img-item {
        width: 100px;
        height: 100px;
        // box-shadow: 0 4px 10px #ddeeffc4;
        border-radius: 18px;
        padding: 16px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }

    .fs-nav-bar_list {
      width: 100%;

      .nav-item {
        width: 100%;
        position: relative;
        padding: 20px 0;
        font-size: 25px;
        font-weight: 700;
        cursor: pointer;
        text-align: center;

        .text {
          position: absolute;
          display: inline-block;
          width: 100%;
          /* transform: translateY(-30px) translate(-50%); */
          transform: translateY(0) translate(-10%);
          opacity: 0;
          left: 50%;
          text-align: center;
          transition: all 0.5s;
        }

        .text-active {
          transform: translateY(0) translate(-50%);
          opacity: 1;
        }

        .icon-active {
          opacity: 0;
        }
      }

      .nav-item:hover span {
        transform: translateY(0) translate(-50%);
        opacity: 1;
      }

      .nav-item:hover .item-icon {
        opacity: 0;
      }
    }
  }
}

.my-element {
  display: inline-block;
  margin: 0 0.5rem;

  animation: flip 2s ease 0s infinite; /* referring directly to the animation's @keyframe declaration */
  // animation-duration: 2s; /* don't forget to set a duration! */
}
</style>
